function promptcommon(title) {
    var mydiv = document.createElement('div');
    mydiv.className = 'tishi';
    mydiv.style.boxSizing = 'border-box';
    mydiv.style.fontSize = '30px';
    mydiv.style.width = '800px';
    mydiv.style.height = '120px';
    mydiv.style.position = 'absolute';
    mydiv.style.background = '#ffe488';
    mydiv.style.zIndex = 1111;
    mydiv.style.top = '280px';
    mydiv.style.left = '300px';
    mydiv.style.lineHeight = '120px';
    mydiv.style.textAlign = 'center';
    mydiv.style.color = 'black';
	mydiv.style.borderRadius = '20px';
	

	var titlediv = document.createElement('div');
	titlediv.style.marginTop = '40%';
	titlediv.style.marginLeft = "40%";

	titlediv.innerText = title;

	mydiv.appendChild(titlediv);
    // mydiv.innerText = title;
    //mydiv.innerText = title;

//$("body").append(str);
document.body.appendChild(mydiv);

setTimeout(function () {
    //document.getElementsByClassName('tishi')[0].style.display='none';
    document.body.removeChild(mydiv);
}, 2000);
};
var env = evm.getStbBrowser();

var typedrive = env.browser;
var elem;
var backurl = getParam('backurl');
var data;
var ifchange;
var answers = [];
// var access_token = EVM.cookie.getValue('serialNumber');
var codes;
var size = 0;
//console.log(urlId)
//var datas =[
//	{id:01,title:"1：您对丹阳市民主党派服务中心工作是否",one:"非常满意",two:"比较满意",three:"满意",four:"不满意"},
//	{id:02,title:"2：奥斯卡级大师级奥凯电缆卡时间段哈就开始发哈",one:"非常满意",two:"比较满意",three:"满意",four:"不满意"},
//	{id:03,title:"按实际快点哈解答",one:"非常满意",two:"比较满意",three:"满意",four:"不满意"},
//]
//console.log(datas)
getDatas()

function getDatas() {
	var ajax;
    if (window.XMLHttpRequest) {
        ajax = new XMLHttpRequest();
    } else {
        ajax = new ActiveXObject('Microsoft.XMLHTTP');
  }
  console.log(api+daTi)
  ajax.open('get', api+daTi + '?base_id=' + getCookie('base_id') , true);
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax.send();
    ajax.onreadystatechange = function () {
        if (ajax.readyState == 4 && ajax.status == 200) {
			var text = ajax.responseText;
			//alert(text);
			
            if (text.length != 0) {
                var response = eval("(" + text + ")");
			}

			data = response.linkres;
			tikuhao = response.library.id
			var bgimg = response.an_img;
			//$("body").css('background', 'url('+(api+bgFirst+bgimg)+') no-repeat left top');
			// document.body.style.backgroundImage = "url("+api+bgFirst+bgimg+")";
   
			var str = "";
			
			if(data.length > 0) {
				change(size)
			}
        }
    }
    // ajax.send('tv_no=' + tv_no + '&tv_card=' + tv_card + '&isalone=' + isalone);
// 	$.ajax({
// 		type: 'get',
// //		url: api + "diaocha/wenjuanList?diaocha_id=" + urlId,
// //http://192.168.3.136:8000/public/upload/admin/20190527/f608506fe784e65d4a7f94e49deded2c.png
// 		url:api+daTi,
// 		dataType: "jsonp",
// 		//			使用jsonp的方式传输数据(能够方便跨域)
// 		jsonp: "callback",
// 		async: false,
// 		success: function(res) {
// 			console.log(res,11111)

// 			//          console.log(data[i].name)

// 			// console.log(res.data, 'res')
// 		},
// 		error: function() {
// 			alert('系统错误');
// 		}
// 	});
}



function change(size) {
	//$(".timuTitle").attr("data-id", data[size].id);
	//promptcommon("library_id:::::"+data[size].id);
	getElementsByClassName('timuTitle')[0].setAttribute('data-id',data[size].id);
	getElementsByClassName('timuTitle')[0].id = data[size].id;
	//$(".title-number").text("第"+(size+1)+"题");
	getElementsByClassName('title-number')[0].innerText = "第"+(size+1)+"题";
	//prompt(getElementsByClassName('title-number'));
	
	/*$(".timuTitle").text(data[size].questions_name)
	$("#option-list1").text("A . "+data[size].answer1)
	$("#option-list2").text("B . "+data[size].answer2)
	$("#option-list3").text("C . "+data[size].answer3)*/

	//promptcommon(getElementsByClassName('timuTitle')[0].id);

	getElementsByClassName('timuTitle')[0].innerText = data[size].questions_name;
	document.getElementById('option-list1').innerText = "A . "+data[size].answer1;
	document.getElementById('option-list2').innerText = "B . "+data[size].answer2;
	document.getElementById('option-list3').innerText = "C . "+data[size].answer3;
	answerTrue=data[size].correct; //取每道题的答案：answerTrue
}

function datas(size, valus) {
	EVM.cookie.setValue(size, valus)
}

function answer() {

	for(var i = 0; i < data.length; i++) {
		value = EVM.cookie.getValue(i);
		answers.push(value)
	}

}

/*
 * $cmsIndex首页视图模块
 * 依赖:
 */
var cmsIndex = (function() {
	var mod = {};

	//配置项
	var config = mod.config = {
		//开启cookie开关
		cookieSwitch: true,
		cookieKey: 'cmsIndex',
		//模拟数据配置
		mockData: {
			//URI查询标示符
			key: '[mdata]',
			//文件目录
			dir: '../source/mockData'
		},
		//调试输出开关
		debug: false
	};

	var localData = mod.localData = {
		indexSource: '[mdata]/index.js'
	};
	//接口数据缓存
	var jsonCache = {};

	//各模块焦点切换的配置
	var modules = mod.modules = [];

	//当前模块的索引值,被引用的模块
	moduleId = 0,
		module = null,
		moduleGuid = 0,
		moduleCount = -1;

	mod.addModule = function() {
		return moduleCount += 1;
	};

	//moduleGuid存取器
	mod.moduleGuid = function(id) {
		if(typeof id == 'number') moduleGuid = id;
		return moduleGuid;
	};

	//添加视图按键管理器
	mod.addListener = function() {
		evm.controller.subscribe({
			type: 1,
			method: 'add',
			callback: mod.grabEvent,
			context: mod
		});
	};
	// console.log(mod)
	//移除视图按键管理器
	mod.removeListener = function() {
		evm.controller.subscribe({
			type: 1,
			method: 'remove',
			callback: mod.grabEvent,
			context: mod
		});
	};
	// console.log(module)
	//视图按键管理

	mod.grabEvent = function(key) {
		var me = mod;
		//拦截返回键,方法返回isBlock是1或0,默认0不拦截
		var isBlock = 0;

		if(module && module.grabEvent) {
			isBlock = module.grabEvent(key) || 0;
		}

		return isBlock;
	};
	//模块存取器
	mod.module = function(mID) {
		if(modules[mID]) {
			module = modules[mID].module || null;
		}

		return module;
	};

	//切换当前模块
	mod.handle = function(directive) {
		var me = mod;
		if(modules[moduleId].map &&
			(typeof modules[moduleId].map[directive] == 'number')) {

			moduleId = modules[moduleId].map[directive];

			return me.module(moduleId);
		}
	};
	mod.paint = function() {
		var me = mod;
		me.addListener();
		return me;
	};

	mod.run = function() {
		var me = mod;
		//默认moduleId = 0 导航栏
		//cookie得到焦点
		me.paint();
		var nav = mod.module(moduleId);
		cmsIndex.handle('indexs');
		indexs.toggleFocus()

		//控制器管理按键
		evm.on(document, (!env.stb ? 'keydown' : (env.stb == 'iPanel' ?
			'irkeypress' : 'keydown')), evm.controller, evm);

		return me;
	};

	return mod;

})();

/*
 * 0.index侧区
 */

cmsIndex.modules[cmsIndex.moduleGuid(cmsIndex.addModule())] = {
	modName: 'indexs',
	modNum: cmsIndex.moduleGuid(),
	map: {
		logins: 1,
	}
};

var indexs = cmsIndex.modules[cmsIndex.moduleGuid()].module = (function() {
	var mod = {},
		loginFlag = 0,
		index = 0, //右侧选中地址位置
		listName = 'option-list',
		length = 3, //框内元素数量
		//      containerId = 'right',
		checkCookie = true; //配置是否定位焦点到二级栏目，默认否

	mod.modName = 'indexs';

	mod.modNum = cmsIndex.moduleGuid();

	mod.celarCss = function() {
		var me = mod;
		elem = $('.' + listName);
		for(i = 0; i < length; i++) {
			elem[i].className = listName;
		}
		return me;
	}

	mod.toggleFocus = function() {
		var me = mod;

		//		getDatas();

		//elem = $('.' + listName);
		elem = getElementsByClassName(listName);
		//var elemFooter = $(".next");
		var elemFooter = getElementsByClassName('next');
		// elemFooter.removeclass("iactive");

		for(i = 0; i < length; i++) {
			elem[i].className = listName;
		}

		if(index == 3) {
			// elemFooter.addClass("iactive");
		}

		if(index >= 0 && index < 3) {

			elem[index].className = elem[index].className + ' iactive';

		}

		if(ifchange != undefined) {
			elem[ifchange].className = elem[ifchange].className + ' iactive ifchange';
		}

		return me;
	};

	function prompt(title) {
		/*str = '<div class="tishi" style="font-size: 26px;z-index: 1111;text-align: ' +
			'center;width: 655px;height: 65px;position: absolute;background: #A40000;padding: 10px;border-radius: 50px;top: 505px;left: 145px;color: #fff75c;border:3px solid #FCF001";>' + title +
			'</div>';
		$("body").append(str);
		setTimeout(function() {
			$('.tishi').hide()
		}, 2500);*/

		var mydiv = document.createElement('div');
		mydiv.className = 'tishi';
		mydiv.style.boxSizing = 'border-box';
		mydiv.style.fontSize = '26px';
		mydiv.style.width = '655px';
		mydiv.style.height = '65px';
		mydiv.style.position = 'absolute';
		mydiv.style.background = '#A40000';
		mydiv.style.zIndex = 1111;
		mydiv.style.top = '505px';
		mydiv.style.left = '145px';
		mydiv.style.lineHeight = '65px';
		mydiv.style.textAlign = 'center';
		mydiv.style.color = '#fff75c';
		mydiv.style.border = "3px solid #FCF001";
		mydiv.style.borderRadius = '50px';
		
		/*var titlediv = document.createElement('div');
		titlediv.style.marginTop = '40%';
		titlediv.style.marginLeft = "40%";*/
	
		mydiv.innerText = title;
	
		//mydiv.appendChild(titlediv);
		// mydiv.innerText = title;
		//mydiv.innerText = title;
	
	//$("body").append(str);
	document.body.appendChild(mydiv);
	
	setTimeout(function () {
		document.body.removeChild(mydiv);
	}, 2500);


	};
	function prompt1(title) {
		/*str = '<div class="tishi" style="font-size: 26px;z-index: 1111;text-align: ' +
			'center;width: 655px;height: 65px;position: absolute;background: #A40000;padding: 10px;border-radius: 50px;top: 505px;left: 145px;color: #fff75c;border:3px solid #FCF001";>' + title +
			'</div>';*/

	    var mydiv = document.createElement('div');
		mydiv.className = 'tishi';
		mydiv.style.boxSizing = 'border-box';
		mydiv.style.fontSize = '26px';
		mydiv.style.width = '655px';
		mydiv.style.height = '65px';
		mydiv.style.position = 'absolute';
		mydiv.style.background = '#A40000';
		mydiv.style.zIndex = 1111;
		mydiv.style.top = '505px';
		mydiv.style.left = '145px';
		mydiv.style.lineHeight = '65px';
		mydiv.style.textAlign = 'center';
		mydiv.style.color = '#fff75c';
		mydiv.style.border = "3px solid #FCF001";
		mydiv.style.borderRadius = '50px';
	
		mydiv.innerText = title;
	//$("body").append(str);
	document.body.appendChild(mydiv);
		//$("body").append(str);
		setTimeout(function() {
			// $('.tishi').hide()
			document.body.removeChild(mydiv);
		}, 2500);
	};
		function prompt3(title) {
		str = '<div class="tishi" style="font-size: 26px;z-index: 1111;text-align: ' +
			'center;width: 655px;height: 65px;position: absolute;background: #A40000;padding: 10px;border-radius: 50px;top: 505px;left: 145px;color: #fff75c;border:3px solid #FCF001";>' + title +
			'</div>';
		//$("body").append(str);

		var mydiv = document.createElement('div');
		mydiv.className = 'tishi';
		mydiv.style.boxSizing = 'border-box';
		mydiv.style.fontSize = '26px';
		mydiv.style.width = '655px';
		mydiv.style.height = '65px';
		mydiv.style.position = 'absolute';
		mydiv.style.background = '#A40000';
		mydiv.style.zIndex = 1111;
		mydiv.style.top = '505px';
		mydiv.style.left = '145px';
		mydiv.style.lineHeight = '65px';
		mydiv.style.textAlign = 'center';
		mydiv.style.color = '#fff75c';
		mydiv.style.border = "3px solid #FCF001";
		mydiv.style.borderRadius = '50px';
	
		mydiv.innerText = title;

		document.body.appendChild(mydiv);
		setTimeout(function() {
			//$('.tishi').hide();
			document.body.removeChild(mydiv);
		}, 10000);
	};
	//赋值
	mod.moveU = function(directive) {
		var me = mod;
if (index!=3) {
	

		if(directive == "up") { //上
			
			if(index > 0) {
				index--
			}
		} else if(directive == "down") { //下
			if(index < 2) {
				index++
			}
		}
		mod.toggleFocus();
}
		
		return me;
	};
	mod.action = function(directive) {
		var me = mod;
		// promptcommon(directive);
		switch(directive) {
			case 'back':
            if (!backurl) {
                Window.location.href = "./index.html"
            } else {
                Window.location.href = decodeURIComponent(backurl)
            }
				break;
			case 'enter':
				//				alert(index)
				//			window.location.href = "index.html";
				
					if(index == 3) {
						
						if(size == data.length - 1) {
							//走接口
							answer();

							//console.info(answers);
							var cardnum = EVM.cookie.getValue('serialNumber');
							var cacardnum = EVM.cookie.getValue('caserialNumber');
// 							var tijiaodata = {
// //								id: urlId,
// 								tv_no : cardnum,
// 								tv_card:cacardnum,
// 								library_id :tikuhao,
// //								access_token: access_token,
// 								answers: answers,
// 							}
							var ajax;
							if (window.XMLHttpRequest) {
								ajax = new XMLHttpRequest();
							} else {
								ajax = new ActiveXObject('Microsoft.XMLHTTP');
							}
							ajax.open('get', api+sendDati+'?tv_no='+cardnum+'&tv_card='+cacardnum+'&answers=' + answers + '&library_id=' + tikuhao + '&base_id=' + getCookie('base_id'), true);
							ajax.setRequestHeader("Content-type", "application/json");
							ajax.send();
							ajax.onreadystatechange = function () {
								
								if (ajax.readyState == 4 && ajax.status == 200) {
									var text = ajax.responseText;
									
								
									if (text.length != 0) {
										var response = eval("(" + text + ")");
									}
									// promptcommon(response.type);
									var answer_rate = response.answer_rate;
									var sum = response.sum;
									if(response.type == 0){
										window.location.href = 'result2.html?sum='+sum+'&answer_rate='+answer_rate;
									}else{
										window.location.href = 'answerTrue.html?sum='+sum+'&answer_rate='+answer_rate;
									}
								}
							}

							/*$.ajax({
								type: 'get',
//								url: api + 'Result/lst', //这里的mid就是需要传进来的id
								url: api+sendDati,
								data: tijiaodata,
								dataType: "json",
								//			使用jsonp的方式传输数据(能够方便跨域)
//								jsonp: "callback",
								async: false,
								success: function(res) {
									//										console.log(res.code)
									//                                       codes =res.code
								var answer_rate = res.answer_rate;
								var sum = res.sum;
//										prompt3("提交成功");
										//console.log(res,1212121212)
										if(res.type == 0){
//											alert(sum)
											window.location.href = 'result2.html?sum='+sum+'&answer_rate='+answer_rate;
										}else{
											window.location.href = 'answerTrue.html?sum='+sum+'&answer_rate='+answer_rate;
										}
//										setTimeout(function() {
//											window.location.href = "index.html"
//										}, 1500)
									

								},
							});*/
							index=0;
						} else {

							if(size == data.length - 2) {
								//$(".next").html("提交");
								getElementsByClassName('next')[0].innerText = '提交';
							}
							size++;
							change(size);
							ifchange = undefined;
							index = 0;
						}
					} else {
						ifchange = index;
//						console.log(answerTrue,99999)

						
						//s = $(".timuTitle").attr("data-id");
						//s = getElementsByClassName('timuTitle')[0].getAttribute('data-id');
						s = getElementsByClassName('timuTitle')[0].id;
						//promptcommon(s);
						//					alert(s)

						switch(ifchange) {
							case 0:
								valus = s + "-A"
								break;
							case 1:
								valus = s + "-B"
								break;
							case 2:
								valus = s + "-C"
								break;
//							case 3:
//								valus = s + "-D"
//								break;
						}
//						console.log(valus.substr(3),00000000000)
						//判断正确与错误：列如：A=A
						// alert(answerTrue)
						// alert(valus.substr(-1,1))

						if(valus.substr(-1,1) != answerTrue){
							//prompt();
							
							prompt("回答错误，正确答案为："+answerTrue+ "，按遥控器上  '确认键' 继续")
						}else{
							prompt1("回答正确，按遥控器上  '确认键' 继续")
						}
						
						datas(size, valus)
						index = 3;
					}

				
				me.toggleFocus()
				break;

		}
		return me;
	};

	mod.grabEvent = function(key) {
		var me = mod;
		//拦截返回键,方法返回isBlock是1或0,默认0不拦截
		var isBlock = 0;
		switch(key) {
			case keymap.Enrich.UP:
			case keymap.iPanel.UP:
			case keymap.DVN.UP:
				me.moveU('up');
				break;
			case keymap.Enrich.DOWN:
			case keymap.iPanel.DOWN:
			case keymap.DVN.DOWN:
				me.moveU('down');
				break;
			case keymap.Enrich.LEFT:
			case keymap.iPanel.LEFT:
			case keymap.DVN.LEFT:
				me.moveH('backwards');

				break;
			case keymap.Enrich.RIGHT:
			case keymap.iPanel.RIGHT:
			case keymap.DVN.RIGHT:
				me.moveH('forwards');

				break;
			case keymap.SELECT:
			case keymap.SELECT2:
				me.action('enter');
				break;
			case keymap.Enrich.BACK:
			case keymap.iPanel.BACK:
			case keymap.DVN.BACK:
				me.action('back');
				break;
			case keymap.Inspur.EXIT:
			case keymap.iPanel.EXIT:
			case 0:
				//				window.location.href = "index.html";
				break;
		}
		return isBlock;
	};

	return mod;
})();

cmsIndex.run();

function getElementsByClassName(className){  
    var elements = [];  

    if(!document.getElementsByClassName){  
        var domNodes = document.getElementsByTagName("*");  
        for(var i =0 ;i<domNodes.length;i++){  
            if(domNodes[i].className){  
                var classNames = domNodes[i].className.split(" "); /*这里其实还要考虑类名间隔大于一个空格的情况*/  
                for(var j = 0;j<classNames.length;j++){  
                    if(classNames[j]==className){  
                        elements.push(domNodes[i]);              
                    }  
                }  
            }  
        }  
    }else{  
　　　　 /*这里既然浏览器支持这个行为，为何不直接return document.getElementsByClassName(className) ？？？*/
        var domNodes = document.getElementsByClassName(className);  
        for(var i =0 ;i<domNodes.length;i++){  
            elements.push(domNodes[i]);      
        }  
    }  
    return elements;  
} 